﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace GLEED2D
{
	[XmlInclude(typeof(TextureItem))]
	[XmlInclude(typeof(RectangleItem))]
	[XmlInclude(typeof(CircleItem))]
	[XmlInclude(typeof(PathItem))]
	public partial class Item
	{
		/// <summary>
		/// The name of this item.
		/// </summary>
		[XmlAttribute()]
		public String Name;

		/// <summary>
		/// Should this item be visible?
		/// </summary>
		[XmlAttribute()]
		public bool Visible;

		/// <summary>
		/// The item's position in world space.
		/// </summary>
		public Vector2 Position;

		/// <summary>
		/// A Dictionary containing any user-defined Properties.
		/// </summary>
		public SerializableDictionary CustomProperties;

		[XmlIgnore()]
		private Item parent = null;

		[XmlIgnore()]
		public Item Parent
		{
			get { return parent; }
			set
			{
				if (parent != null)
					parent.Children.Remove(this);

				if (value == null)
					parent = null;
				else if(!value.Children.Contains(this))
				{
					parent = value;
					parent.Children.Add(this);
				}
			}
		}

		public List<Item> Children;

		public Item()
		{
			CustomProperties = new SerializableDictionary();
			Children = new List<Item>();
		}

		public void addChild(Item item)
		{
			item.Parent = this;
		}

		public void removeFromParent()
		{
			Parent = null;
		}



		/// <summary>
		/// Called by Level.FromFile(filename) on each Item after the deserialization process.
		/// Should be overriden and can be used to load anything needed by the Item (e.g. a texture).
		/// </summary>
		public virtual void load(ContentManager cm)
		{
		}

		public virtual void draw(SpriteBatch sb)
		{
		}
    }
}
